<?php

namespace IDock\Insurance\ZFIC\Response;

use IDock\Http\Response;
use IDock\IDock\IDockEnums;
use IDock\Insurance\ZFIC\Response\AllZFICResponse;
use IDock\Insurance\ZFIC\ZFICEnums;
use IDock\Printer\VehicleModelPrinter;
use IDock\Printer\VehiclePrinter;

class VehicleModelBXResponse extends CommonResponse
{
    public $totalCount = 0;

    /**
     * @var  $printer VehicleModelPrinter
     */
    public $printer;

    public function printerInit() :Response
    {
        $vehicleModelPrinter = new VehicleModelPrinter();
        $data = $this->getBody()['data'] ?? [];
        $list = $data['CarModelDetialList'] ?? [];

        $QueryVehicleRecognition = $data['QueryVehicleRecognition'] ?? [];


        if(!empty($list)) foreach ($list as $datum){
            $vehiclePrinter = new VehiclePrinter();
            $vehiclePrinter->vehicleModelCode = $datum['VehicleCode'] ?? '';
            $vehiclePrinter->brandName = $datum['BrandNameVeh'] ?? '';
            $vehiclePrinter->vehicleExhaust = round(intval($datum['VehicleDisplacement'] ?? '0') ,3);
            $vehiclePrinter->vehicleImport = 'I0';
            $vehiclePrinter->vehicleName = $datum['BrandModel'] ?? '';
            $vehiclePrinter->vehiclePrice = ($datum['CarValue'] ?? '') ?: $QueryVehicleRecognition['ReplacementValue'] ?? '';
            $vehiclePrinter->vehiclePriceWithOutTax = ($datum['CarValue'] ?? '') ?: $QueryVehicleRecognition['ReplacementValue'] ?? '';
            $vehiclePrinter->vehicleSeat = $datum['LimitLoadPersons'] ?? '';
            $vehiclePrinter->familyName = $datum['FamilyName'] ?? '';
            $vehiclePrinter->power = $QueryVehicleRecognition['Power'] ?? 0;
            $vehiclePrinter->vehicleYear = $datum['YearKx'] ?? '';
            $vehiclePrinter->vehicleTonnage = $datum['RatedContainedMass'] ?? '';
            $vehiclePrinter->wholeWeight = $datum['CurbWeight'] ?? '';
            $vehiclePrinter->remark = $datum['VehicleStyle'] ??'';
            $fuelType = $datum['FuelType'] ?? '';
            $typeCode = array_search($fuelType,ZFICEnums::$energyType);
            $vehiclePrinter->energyTypeCode =  $typeCode ?: 'E00';
            $vehiclePrinter->energyTypeName = $fuelType;
            $vehiclePrinter->item['fueltype'] = $fuelType;//存下燃油类型是汽油还是柴油
            $vehiclePrinter->item['carName'] = $datum['VehicleStyle'] ?? '';
            $vehiclePrinter->item['brandName'] = $datum['BrandModel'] ?? '';
            $vehiclePrinter->item['familyName'] = $datum['VehicleName'] ?? '';
            $vehiclePrinter->item['printBrandName'] = $datum['BrandModel'] ?? '';
            $vehiclePrinter->item['carBrand'] = $datum['BrandName'] ?? '';
            $vehiclePrinter->item['noticeType'] = $datum['ModelCode'] ?? '';
            $vehiclePrinter->item['pk'] = $datum['PK'] ?? '';

            $vehiclePrinter->item['modelType'] = '1';
            if($fuelType == '电动' or $fuelType == '插电式混合动力' or $fuelType == '燃料电池'){
                $vehiclePrinter->isNewEnergy = '1';
            }

            $vehicleModelPrinter->setModelList($vehiclePrinter);
        }
        $this->printer = $vehicleModelPrinter;

        return $this;
    }
}
